---@class ui_data
---@field uid Str ui ID
---@field player GT.player 玩家
---@field u_type Int32 ui类型
---@field pos vec2 坐标
---@field scale size 缩放
---@field parent Str 父节点
---@field opacity Float 透明度
---@field z_order Int32 深度
---@field alignment_type GT.ui.align 组件对齐方式
---@field show Bool ui显示/隐藏
---@field isdrag boolean 是否可拖动
---@field intercepts boolean 是否拦截操作
---@field rot float 相对旋转角度
---@field absolute_pos vec2 绝对坐标
---@field absolute_rot float 绝对旋转角度
---@field absolute_scale vec2 绝对缩放
---@field relative_scale vec2 相对缩放
---@field suspend_image Int32 ui组件悬浮态图片
---@field press_image Int32 ui组件按下态图片
---@field disabled_image Int32 ui组件禁用态图片
---@field click UI_EVENT 点击
---@field double_click UI_EVENT 双击
---@field hover UI_EVENT 悬浮
---@field leave UI_EVENT 离开
---@field enter UI_EVENT 进入
---@field long_press UI_EVENT 长按
---@field creates ui_event_create 创建ui事件(创建后)
---@field dels ui_event_del 删除ui事件(删除前)
---@field x Int32
---@field y Int32
---@field w Int32 宽
---@field h Int32 高
---@field open Bool ui是否开启
---@field is_data_driven Bool 是否注册独立数据驱动(在 uid不为nil的情况下使用)





---@param data ui_data
---@return GT.ui
function GT.ui:ctor(data)
    self.player = data.player or GT.player.get_loc_player()
    self.class = data.class or GT.ui
    data.class=data.class or GT.ui
    if self.u == nil then
        self.u = {}
    end
    if data.uid ~= nil then
        self.uid = data.uid

        self.x = data.x or self:get_widget_absolute_x_coordinate() or 0
        self.y = data.y or self:get_widget_absolute_y_coordinate() or 0
        self.w = data.w or self:get_w() or 0
        self.h = data.h or self:get_h() or 0


        if data.is_data_driven then
            self:data_driven(data)
        end
    else
        self.parent = data.parent or "panel_2"
        self.x = data.x or 0
        self.y = data.y or 0
        self.w = data.w or 0
        self.h = data.h or 0

        self.u_type = data.u_type
        self.dels = data.dels
        self.creates = data.creates
        self.show = data.show
        self.scale = data.scale or {}
        self.opacity = data.opacity
        self.isdrag = data.isdrag
        self.intercepts = data.intercepts
        self.rot = data.rot
        self.absolute_pos = data.absolute_pos
        self.absolute_rot = data.absolute_rot
        self.absolute_scale = data.absolute_scale
        self.relative_scale = data.relative_scale
        self.suspend_image = data.suspend_image
        self.press_image = data.press_image
        self.disabled_image = data.disabled_image
        self.z_order = data.z_order
        self.alignment_type = data.alignment_type
        self.open = data.open
        if self.module == nil then
            self.uid = self:create()
            self:data_driven(data)
        end
        self:init(data)
    end
    if self.uid ~= nil then
        --热更新 执行的函数
        hotfun[self.uid] = function()
            self:dtor()
        end
        self:ui_watch()
    end


    return self
end

---玩家独立数据驱动
---@param data any
function GT.ui:data_driven(data)
    data.is_data_driven = false
    local p = GT.playerGroup.get_all_role_ids():pick()
    for pk, pv in pairs(p) do
        data.uid = self.uid
        data.player = pv
        self.u[pv.pid] = new(data.class, data)
    end
end

---转对象
---@param data ui_data
---@return GT.ui
function GT.ui.obj(data)
    return new(GT.ui, data)
end

---获取子UI
---@param path Str 路径
---@return Str uid
function GT.ui:get_child_uid(path)
    return GT.ui.get_comp_by_path(self.player, self.uid, path)
end

---@param data ui_data
function GT.ui:init(data)
    if self.z_order ~= nil then
        self:set_z_order(self.z_order)
    end
    --设置尺寸
    if self.w ~= nil and self.w ~= 0 then
        self:set_size(self.w, self.h)
    end
    if self.x ~= nil and self.x ~= 0 then
        self:set_pos(self.x, self.y)
    end
    if data.click then
        self:click(data.click)
    end
    if data.double_click then
        self:double_click(data.double_click)
    end
    if data.enter then
        self:enter(data.enter)
    end
    if data.hover then
        self:hover(data.hover)
    end
    if data.leave then
        self:leave(data.leave)
    end
    if data.long_press then
        self:long_press(data.long_press)
    end

    if self.show ~= nil then
        self:set_show(self.show)
    end
    if self.opacity ~= nil then
        self:set_opacity(self.opacity)
    end
    if self.isdrag ~= nil then
        self:set_is_draggable(self.isdrag)
    end
    if self.intercepts ~= nil then
        self:set_intercepts_operations(self.intercepts)
    end
    if self.rot ~= nil then
        self:set_widget_relative_rotation(self.rot)
    end
    if self.absolute_pos ~= nil then
        self:set_widget_absolute_pos(self.absolute_pos)
    end
    if self.absolute_rot ~= nil then
        self:set_widget_absolute_rotation(self.absolute_rot)
    end
    if self.absolute_scale ~= nil then
        self:set_widget_absolute_scale(self.absolute_scale)
    end
    if self.relative_scale ~= nil then
        self:set_widget_relative_scale(self.relative_scale)
    end
    if self.suspend_image ~= nil then
        self:set_suspend_image(self.suspend_image)
    end
    if self.press_image ~= nil then
        self:set_press_image(self.press_image)
    end
    if self.disabled_image ~= nil then
        self:set_disabled_image(self.disabled_image)
    end
    if self.alignment_type ~= nil then
        self:set_alignment_type_for_ui_widget(self.alignment_type)
    end
    if self.creates then
        self.creates(self)
    end
    if self.open ~= nil then
        self:set_open(self.open)
    end
end

---监听绑定
function GT.ui:ui_watch()
    self.bind = new(bind, self)

    ---@type GT.ui
    self.binding = self.bind.bindable
    self.bind:add({
        {
            key = "x",
            func = function(val, old)
                self.x = val

                self:set_pos(self.x, self.y)
            end
        },
        {
            key = "y",
            func = function(val, old)
                self.y = val

                self:set_pos(self.x, self.y)
            end
        },
        {
            key = "w",
            func = function(val, old)
                self.w = val
                self:set_size(self.w, self.h)
            end
        },
        {
            key = "h",
            func = function(val, old)
                self.h = val
                self:set_size(self.w, self.h)
            end
        },
        {
            key = "show",
            func = function(val, old)
                self.show = val

                self:set_show(self.show)
            end
        },

        {
            key = "scale",
            func = function(val, old)
                self.scale = val
                self:set_scale(self.scale)
            end
        },
        {
            key = "opacity",
            func = function(val, old)
                self.opacity = val
                self:set_opacity(self.opacity)
            end
        },
        {
            key = "isdrag",
            func = function(val, old)
                self.isdrag = val
                self:set_is_draggable(self.isdrag)
            end
        },
        {
            key = "intercepts",
            func = function(val, old)
                self.intercepts = val
                self:set_intercepts_operations(self.intercepts)
            end
        },
        {
            key = "rot",
            func = function(val, old)
                self.rot = val
                self:set_widget_relative_rotation(self.rot)
            end
        },
        {
            key = "absolute_pos",
            func = function(val, old)
                self.absolute_pos = val
                self:set_widget_absolute_pos(self.absolute_pos)
            end
        },
        {
            key = "absolute_rot",
            func = function(val, old)
                self.absolute_rot = val
                self:set_widget_absolute_rotation(self.absolute_rot)
            end
        },
        {
            key = "absolute_scale",
            func = function(val, old)
                self.absolute_scale = val
                self:set_widget_absolute_scale(self.absolute_scale)
            end
        },
        {
            key = "relative_scale",
            func = function(val, old)
                self.relative_scale = val
                self:set_widget_relative_scale(self.relative_scale)
            end
        },
        {
            key = "suspend_image",
            func = function(val, old)
                self.suspend_image = val
                self:set_suspend_image(self.suspend_image)
            end
        },
        {
            key = "press_image",
            func = function(val, old)
                self.press_image = val
                self:set_press_image(self.press_image)
            end
        },
        {
            key = "disabled_image",
            func = function(val, old)
                self.disabled_image = val
                self:set_disabled_image(self.disabled_image)
            end
        },
        {
            key = "z_order",
            func = function(val, old)
                self.z_order = val
                self:set_z_order(self.z_order)
            end
        },
        {
            key = "alignment_type",
            func = function(val, old)
                self.alignment_type = val
                self:set_alignment_type_for_ui_widget(self.alignment_type)
            end
        },
        {
            key = "open",
            func = function(val, old)
                self.open = val
                self:set_open(self.open)
            end
        }



    })
end

function GT.ui:dtor()
    if GT.debug then
        print_debug("删除ui：" .. tostring(self.uid))
    end
    self.bind:dtor()
    self:del()
    self = nil
end

---@generic T
---通过控件获得子ui
---@param control T 对象
---@param path Str 路径
---@return T
function GT.ui:get_child(control, path)
    return new(control, {
        player = self.player,
        uid = GT.ui.get_comp_by_path(self.player.player, self.uid, path),
        is_data_driven = true
    })
end

---@generic T
---通过绝对路径获得ui
---@param control T 对象
---@param path Str 路径
---@param player GT.player 路径
---@return T
function GT.ui.get_child_absolute(control, path, player)
    return new(control, {
        player = player,
        uid = GT.ui.get_uid_absolute(player, path),
        is_data_driven = true
    })
end

--- 创建ui控件
---@param comp_name Str 父节点
---@param comp_type Int32 控件类型
---@return Str
function GT.ui:create()
    return game_api.create_ui_comp(self.player.player, self.get_uid_absolute(self.player, self.parent) or self.parent,
        self.u_type)
end

--- 删除界面控件
function GT.ui:del()
    if self.dels then
        self.dels(self)()
    end
    game_api.del_ui_comp(self.player.player, self.uid)
end

--- 设置ui组件尺寸
---@param width Float width
---@param height Float height
---@return GT.ui
function GT.ui:set_size(width, height)
    game_api.set_ui_comp_size(self.player.player, self.uid, width, height)
    return self
end

--- 设置ui组件坐标
---@param x Float x
---@param y Float y
---@return GT.ui
function GT.ui:set_pos(x, y)
    game_api.set_ui_comp_pos(self.player.player, self.uid, Fix32(x), Fix32(y))
    return self
end

--- 设置ui显示/隐藏
---@param visible Bool 显/隐
---@return GT.ui
function GT.ui:set_show(visible)
    game_api.set_ui_comp_visible(self.player.player, visible, self.uid)
end

--- 获得玩家控件显隐性
---@return Bool
function GT.ui:is_show()
    return game_api.get_ui_comp_visible(self.player.player, self.uid)
end

--- 获得控件宽度
---@return Int32
function GT.ui:get_w()
    return game_api.get_ui_comp_width(self.uid)
end

--- 获得控件高度
---@return Int32
function GT.ui:get_h()
    return game_api.get_ui_comp_height(self.uid)
end

--- 获取ui控件的名称
---@return Str
function GT.ui:get_ui_name()
    return game_api.get_ui_comp_name(self.player.player, self.uid)
end

--- 解绑绑定控件
---@return GT.ui
function GT.ui:unbind_ui()
    game_api.unbind_ui_comp(self.player.player, self.uide)
    return self
end

--- 设置ui组件缩放
---@param scale size
---@return GT.ui
function GT.ui:set_scale(scale)
    game_api.set_ui_comp_scale(self.player.player, self.uid, scale.w, scale.h)
    return self
end

--- 设置ui组件深度
---@param z_order Int32 z_order
---@return GT.ui
function GT.ui:set_z_order(z_order)
    game_api.set_ui_comp_z_order(self.player.player, self.uid, z_order)
    return self
end

--- 设置ui开启/关闭
---@param current_value Bool 是否开启
---@return GT.ui
function GT.ui:set_open(current_value)
    game_api.set_ui_comp_enable(self.player.player, self.uid, current_value)
    return self
end

--- 设置控件透明度
---@param opacity Float 透明度
---@return GT.ui
function GT.ui:set_opacity(opacity)
    game_api.set_ui_comp_opacity(self.player.player, self.uid, opacity)
    return self
end

--- 创建并绑定ui控件事件
---@param event_type Int32 控件事件类型
---@return Str
function GT.ui:events(event_type)
    return game_api.create_ui_comp_event(self.player.player, self.uid, event_type)
end

--- 新版创建并绑定ui控件事件(指定事件名),不再传入玩家，同时支持普通控件和动态创建控件
---@param event_type Int32 控件事件类型
---@param event_name Str 自定义事件名
---@param fun UI_EVENT 执行事件
---@return Str 事件名
function GT.ui:event_ex_ex(event_type, event_name, fun)
    local str = game_api.create_ui_comp_event_ex_ex(self.uid, event_type, event_name)
    local e_str = y3.game:event({ GlobalEventType.UI_EVENT, event_name }, function(data, obj)
        --"data" = {'__ui_event_name': 'a9ae28a3-5acb-55a5-d2ea-1f6ce9ea31e6', '__comp_name': '482a5bb1-a60c-4a3a-8c7b-673b801b15ef', '__role_id': 1}
        fun(data, GT.player.get_by_int(obj.data.__role_id), self)
    end)
    return e_str
end

---点击事件
---@param fun UI_EVENT 执行事件
---@return GT.ui
function GT.ui:click(fun)
    self:event_ex_ex(GT.ui.event['点击'], uuid(), fun)
    return self
end

---双击事件
---@param fun UI_EVENT 执行事件
---@return GT.ui
function GT.ui:double_click(fun)
    self:event_ex_ex(GT.ui.event['双击'], uuid(), fun)
    return self
end

---悬停事件
---@param fun UI_EVENT 执行事件
---@return GT.ui
function GT.ui:hover(fun)
    self:event_ex_ex(GT.ui.event['悬停'], uuid(), fun)
    return self
end

---离开事件
---@param fun UI_EVENT 执行事件
---@return GT.ui
function GT.ui:leave(fun)
    self:event_ex_ex(GT.ui.event['离开'], uuid(), fun)
    return self
end

---进入事件
---@param fun UI_EVENT 执行事件
---@return GT.ui
function GT.ui:enter(fun)
    self:event_ex_ex(GT.ui.event['进入'], uuid(), fun)
    return self
end

---长按事件
---@param fun UI_EVENT 执行事件
---@return GT.ui
function GT.ui:long_press(fun)
    self:event_ex_ex(GT.ui.event['长按'], uuid(), fun)
    return self
end

---设置界面组件的对齐方式
---@param  type integer 对齐方式
function GT.ui:set_alignment_type_for_ui_widget(type)
    game_api.set_ui_comp_align(self.player.player, self.uid, type)
    return self
end

---设置控件是否可拖动
---@param  isdrag boolean 是否可拖动
function GT.ui:set_is_draggable(isdrag)
    game_api.set_ui_comp_drag(self.player.player, self.uid, isdrag)
    return self
end

---设置控件是否拦截操作
---@param  intercepts boolean 是否拦截操作
function GT.ui:set_intercepts_operations(intercepts)
    game_api.set_ui_comp_swallow(self.player.player, self.uid, intercepts)
    return self
end

--设置控件相对旋转
---@param  rot float 角度
function GT.ui:set_widget_relative_rotation(rot)
    game_api.set_ui_comp_rotation(self.player.player, self.uid, Fix32(rot))
    return self
end

---设置控件绝对坐标
---@param absolute_pos vec2 绝对坐标
---@return GT.ui
function GT.ui:set_widget_absolute_pos(absolute_pos)
    game_api.set_ui_comp_world_pos(self.player.player, self.uid, Fix32(absolute_pos.x), Fix32(absolute_pos.y))
    return self
end

--设置控件绝对旋转
---@param  absolute_rot float 角度
function GT.ui:set_widget_absolute_rotation(absolute_rot)
    game_api.set_ui_comp_world_rotation(self.player.player, self.uid, Fix32(absolute_rot))
    return self
end

--设置控件绝对缩放
---@param absolute_scale vec2
function GT.ui:set_widget_absolute_scale(absolute_scale)
    game_api.set_ui_comp_world_scale(self.player.player, self.uid, Fix32(absolute_scale.x), Fix32(absolute_scale.y))
    return self
end

--设置控件相对缩放
---@param relative_scale vec2 相对缩放
function GT.ui:set_widget_relative_scale(relative_scale)
    game_api.set_ui_comp_scale(self.player.player, self.uid, Fix32(relative_scale.x), Fix32(relative_scale.y))
    return self
end

--- 设置默认游戏界面的开关
---@param visible Bool 显隐
function GT.ui.set_prefab_ui_show(player, visible)
    game_api.set_prefab_ui_visible(player, visible)
end

--遍历某个界面控件的子节点
---@return table boolean 遍历到的ui对象
function GT.ui:get_ui_comp_children()
    local lua_table = {}
    local py_list = game_api.get_ui_comp_children(self.player.player, self.uid)
    for i = 1, python_len(py_list) - 1 do
        local iter_ui = python_index(py_list, i)
        table.insert(lua_table, ui.get_lua_ui_from_py(self.player.player, iter_ui))
    end
    return lua_table
end

---获取本地控件相对坐标的X
---@return float x x相对坐标
function GT.ui:get_widget_relative_x_coordinate()
    return game_api.get_ui_comp_pos_x(self.uid):float()
end

---@return float y y相对坐标
--获取本地控件相对坐标的Y
function GT.ui:get_widget_relative_y_coordinate()
    return game_api.get_ui_comp_pos_y(self.uid):float()
end

---@return float x x绝对坐标
--获取本地控件绝对坐标的X
function GT.ui:get_widget_absolute_x_coordinate()
    if self:is_show() == false then
        return game_api.get_ui_comp_world_pos_x(self.uid):float()
    else
        return 0
    end
end

---@return float y y绝对坐标
--获取本地控件绝对坐标的Y
function GT.ui:get_widget_absolute_y_coordinate()
    if self:is_show() == false then
        return game_api.get_ui_comp_world_pos_y(self.uid):float()
    else
        return 0
    end
end

---@return float rot 相对旋转
--获取本地控件相对旋转
function GT.ui:get_widget_relative_rotation()
    return game_api.get_ui_comp_rotation(self.uid)
end

---@return float rot 绝对旋转
--获取本地控件绝对旋转
function GT.ui:get_widget_absolute_rotation()
    return game_api.get_ui_comp_world_rotation(self.uid)
end

---@return float x x相对缩放
--获取本地控件相对缩放的X
function GT.ui:get_widget_relative_scale_x_coordinate()
    return game_api.get_ui_comp_scale_x(self.uid)
end

---@return float y y相对缩放
--获取本地控件相对缩放的Y
function GT.ui:get_widget_relative_scale_y_coordinate()
    return game_api.get_ui_comp_scale_y(self.uid)
end

---@return float x x绝对缩放
--获取本地控件绝对缩放的X
function GT.ui:get_widget_absolute_scale_x_coordinate()
    return game_api.get_ui_comp_world_scale_x(self.uid)
end

---@return float y y绝对缩放
--获取本地控件绝对缩放的Y
function GT.ui:get_widget_absolute_scale_y_coordinate()
    return game_api.get_ui_comp_world_scale_y(self.uid)
end

---@return string str 字符串
--界面控件转化为字符串
function GT.ui:convert_ui_widget_to_string()
    return global_api.comp_to_str(self.uid)
end

--获得界面控件的父控件
---@return Str ui_comp ui控件
function GT.ui:get_parent_widget_of_ui_widget()
    return game_api.get_ui_comp_parent(self.player.player, self.uid)
end

--- 通过绝对路径获得ui控件
---@param role GT.player 玩家
---@param path Str 路径
---@return Str
function GT.ui.get_uid_absolute(role, path)
    local p = game_api.get_comp_by_absolute_path(role.player, tostring(path))
    if p == "nil" then
        p = nil
    end
    return p
end

--- 通过控件+路径获得ui控件
---@param role GT.player 玩家
---@param comp_name Str 父节点
---@param path Str 路径
---@return Str
function GT.ui.get_comp_by_path(role, comp_name, path)
    return game_api.get_comp_by_path(role.player, comp_name, path)
end

--- 界面组件转字符串
---@return Str
function GT.ui:tostring()
    return game_api.ui_comp_to_str(self.uid)
end

--- 界面组件是否存在
---@return Str
function GT.ui.ui_comp_is_exist(uid)
    return game_api.ui_comp_is_exist(uid)
end

--- 通过界面模块+路径获得ui控件
---@param prefab_ins UIPrefabIns 预制
---@param path Str 路径
---@return Str
function GT.ui.get_ui_prefab_child_by_path(prefab_ins, path)
    return game_api.get_ui_prefab_child_by_path(prefab_ins, path)
end

--- 隐藏ui组件并播放动画
---@param anim_name Str 动画名
function GT.ui:hide_ui_comp_animation(anim_name)
    return game_api.hide_ui_comp_animation(self.player.player, self.uid, anim_name)
end

--- 删除界面预制实例
function GT.ui:del_ui_prefab()
    game_api.del_ui_prefab(self.model_uid)
end

--- 获得界面控件所属的界面模块实例(如果是的话)
---@return UIPrefabIns
function GT.ui:get_ui_comp_prefab()
    return game_api.get_ui_comp_prefab(self.player.player, self.uid)
end

--- 设置聊天控件的频道为同盟或者所有人
---@param role Role 玩家
---@param comp_name Str 控件uid
---@param is_ally Bool 是否为同盟
function set_ui_comp_chat_channel(role, comp_name, is_ally)
    game_api.set_ui_comp_chat_channel(role, comp_name, is_ally)
end

--- 绑定单位属性或者全局变量到玩家界面控件的属性
---@param role Role 玩家
---@param ui_comp Str 控件uid
---@param ui_comp_attr Str 控件属性字段
---@param attr_or_var Str 属性名
---@param precision Int32 保留小数精度
function set_ui_comp_bind_attr(role, ui_comp, ui_comp_attr, attr_or_var, precision)
    game_api.set_ui_comp_bind_attr(role, ui_comp, ui_comp_attr, attr_or_var, precision)
end

--- 绑定单位属性或者全局变量到玩家界面控件的属性
---@param role Role 玩家
---@param ui_comp Str 控件uid
---@param ui_comp_attr Str 控件属性字段
---@param attr_or_var Str 属性名
---@param precision Int32 保留小数精度
function set_ui_comp_bind_var(role, ui_comp, ui_comp_attr, attr_or_var, precision)
    game_api.set_ui_comp_bind_var(role, ui_comp, ui_comp_attr, attr_or_var, precision)
end

--- 解绑界面控件属性绑定
---@param ui_comp_attr Str 控件属性字段
function GT.ui:ui_comp_unbind(ui_comp_attr)
    game_api.ui_comp_unbind(self.player.player, self.uid, ui_comp_attr)
end

--- 界面控件属性绑定指定单位
---@param role Role 玩家
---@param ui_comp Str 控件uid
---@param unit Unit 单位
function GT.ui:ui_comp_bind_unit(unit)
    game_api.ui_comp_bind_unit(self.player.player, self.uid, unit)
end

--- 界面控件属性动态绑定主控单位
function GT.ui:ui_comp_bind_ctrl_unit()
    game_api.ui_comp_bind_ctrl_unit(self.player.player, self.uid)
end

--- 绑定玩家属性到玩家界面控件的属性
---@param ui_comp_attr Str 控件属性字段
---@param bind_role Role 玩家
---@param attr_or_var Str 玩家属性key
---@param precision Int32 保留小数精度
function GT.ui:set_ui_comp_bind_player_prop(ui_comp_attr, bind_role, attr_or_var, precision)
    game_api.set_ui_comp_bind_player_prop(self.player.player, self.uid, ui_comp_attr, bind_role, attr_or_var, precision)
end

--- 注册界面控件播放指定动效回调
---@param fx_id Int32 控件动效工程id
---@param ani_name Str 动效名
---@param frame Int32 播放动效回调帧数
---@param handler Str 回调句柄
function GT.ui:register_ui_comp_fx_cb(fx_id, ani_name, frame, handler)
    game_api.register_ui_comp_fx_cb(self.player.player, self.uid, fx_id, ani_name, frame, handler)
end

--- 绑定技能cd到玩家界面控件的属性
---@param ui_comp_attr Str 控件属性字段
---@param ability Ability 技能实体对象
function GT.ui:set_ui_comp_bind_ability_cd(ui_comp_attr, ability)
    game_api.set_ui_comp_bind_ability_cd(self.player.player, self.uid, ui_comp_attr, ability)
end

--- 绑定魔法效果cd到玩家界面控件的属性
---@param ui_comp_attr Str 控件属性字段
---@param modifier ModifierEntity 技能实体对象
function GT.ui:set_ui_comp_bind_modifier_cd(ui_comp_attr, modifier)
    game_api.set_ui_comp_bind_modifier_cd(self.player.player, self.uid, ui_comp_attr, modifier)
end

--- 播放ui动效
---@param role Role 玩家
---@param uid Str 控件uid
---@param fx_id Int32 控件动效工程id
---@param ani_name Str 动效名
function GT.ui:play_ui_comp_fx(fx_id, ani_name)
    game_api.get_comp_by_absolute_path(self.player.player, self.uid, fx_id, ani_name)
end

---@param  point GT.point 点
---@param  harm_type integer 跳字类型
---@param  str string 文字
---@param  player_group player_group 玩家组
--创建悬浮文字
function GT.ui.create_floating_text(point, harm_type, str, player_group)
    game_api.create_harm_text(point.point, harm_type, str, player_group)
end

--- 根据uid获取场景ui中的控件
---@param scene_node_entity GT.ui.scene 场景点
---@param comp_uid Str 模板控件uid
---@return GT.ui
function GT.ui.get_ui_comp_in_scene_ui_ex(scene_node_entity, comp_uid)
    ---@type GT.ui
    local data = {
        uid = game_api.get_ui_comp_in_scene_ui_ex(scene_node_entity.scene, comp_uid)
    }

    return new(GT.ui, data)
end

--绑定单位属性到玩家界面控件的属性
---@param  uiAttr integer 界面控件属性
---@param  attr integer 单位属性
---@param  accuracy integer 小数精度
function GT.ui:bind_unit_attribute_to_player_ui_widget_attribute(uiAttr, attr, accuracy)
    local x = accuracy or 0
    game_api.set_ui_comp_bind_attr(self.player.player, self.uid, uiAttr, attr, x)
end

--界面控件属性绑定指定单位
---@param  unit GT.unit 单位
function GT.ui:ui_widget_attribute_bound_to_specified_unit(unit)
    game_api.ui_comp_bind_unit(self.player.player, self.uid, unit.unit)
end
